﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;
namespace DAO
{
    public class NhanVienDAO
    {
        DataProvider dp = new DataProvider();

        public DataTable LoadDSNhanVien()
        {
            return dp.SqlExcuteQuery("sp_LoadDSNhanVien");
        }

        //Them mot nhan vien moi
        public void ThemNhanVien(NhanVienDTO nvDTO)
        {
            SqlParameter[] pram = {new SqlParameter ("@MaNV",nvDTO.MaNV ),
                                      new SqlParameter ("@HoTen",nvDTO.HoTen ),
                                      new SqlParameter ("@NgaySinh",nvDTO.NgaySinh ),
                                      new SqlParameter ("@CMND",nvDTO.CMND ),
                                      new SqlParameter ("@GioiTinh",nvDTO.GioiTinh ),
                                      new SqlParameter ("@DiaChi",nvDTO.DiaChi ),
                                      new SqlParameter ("@MaChucVu",nvDTO.MaChucVu ),
                                      new SqlParameter ("@MaTinhTrang",nvDTO.MaTinhTrang )
                                  };
            dp.SqlExcuteNonQuery("sp_ThemNhanVien", pram);
        }
        //Xoa mot nhan vien
        public void XoaMotNV(string manv)
        {
            SqlParameter pram = new SqlParameter("@MaNV", manv);
            dp.SqlExcuteNonQuery("sp_XoaNhanVien", pram);
        }
        //Sua mot nhan vien
        public void SuaNhanVien(NhanVienDTO nvDTO)
        {
            SqlParameter[] pram = {new SqlParameter ("@MaNV",nvDTO.MaNV ),
                                      new SqlParameter ("@HoTen",nvDTO.HoTen ),
                                      new SqlParameter ("@NgaySinh",nvDTO.NgaySinh ),
                                      new SqlParameter ("@CMND",nvDTO.CMND ),
                                      new SqlParameter ("@GioiTinh",nvDTO.GioiTinh ),
                                      new SqlParameter ("@DiaChi",nvDTO.DiaChi ),
                                      new SqlParameter ("@MaChucVu",nvDTO.MaChucVu ),
                                      new SqlParameter ("@MaTinhTrang",nvDTO.MaTinhTrang )
                                  };
            dp.SqlExcuteNonQuery("sp_SuaNhanVien", pram);
        }
        //tim kiem theo nhan vien
        public DataTable TimTheoTenNV(string ten)
        {
            SqlParameter param = new SqlParameter("@Ten", ten);
            return dp.SqlExcuteQuery("sp_TimTheoTenNV", param);
        }
        //tim theo ma nhan vien
        public DataTable TimTheoMaNV(string ma)
        {
            SqlParameter param = new SqlParameter("@Ma", ma);
            return dp.SqlExcuteQuery("sp_TimTheoMaNV", param);
        }

        //tim theo dia chi
        public DataTable TimTheoDiaChiNV(string dc)
        {
            SqlParameter param = new SqlParameter("@diachi", dc);
            return dp.SqlExcuteQuery("sp_TimTheoDiaChiNV", param);
        }
        //tim theo ma chuc vu
        public DataTable TimTheoMaChucVuNV(string cv)
        {
            SqlParameter param = new SqlParameter("@macv", cv);
            return dp.SqlExcuteQuery("sp_TimTheoMaChucVuNV", param);
        }
    }
}
